
//
// 101020 - AH - Created.
// 101021a- AH - More partial implementation done: 
//               match(List<AttributeObject> input) (ready for testing).
// 101021b- AH - Changes related to Spoke.101021b.
// 101022 - AH - Done with the single tag match case, nothing tested yet.
// 101116a- AH - Removed retrieval strategy code that was started here; we
//               ended up implementing that in the utility class
//               MineRetrievalStrategy, this is now implemented in terms of 
//               that.
// 101116b- AH - getMine().
// 110109 - AH - (Hector) Introducing the RetrievalEvent.
// 110110 - AH - Implemented new Spoke method getInput(List<AttributeObject>).
// 110117 - AH - (Hector) Renamed getInput(List<AttributeObject>) to
//               getToken(List<AttributeObject>) to be true to terminology.
// 110709 - AH - (Garage) getOnotology().
// 120117 - AH - (Huset) Renamed from *Spoke.
// 120228 - AH - (Zen *) Implemented new Ontology method 
//               getSoekratNames(List<SoekratNames>).
//

package org.soekrat.engine.wheel.ontology;

import java.util.ArrayList;
import java.util.List;

import org.soekrat.AttributeObject;
import org.soekrat.engine.SoekratName;
import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.mine.Resource;
import org.soekrat.engine.mine.Tags;
import org.soekrat.engine.ontology.OntologyDatastructure;
import org.soekrat.engine.retrieval.mine.MineRetrievalStrategy;
import org.soekrat.engine.retrieval.mine.MineScan;
import org.soekrat.engine.visitor.Input;
import org.soekrat.engine.wheel.Wheel;
import org.soekrat.engine.wheel.retrieval.RetrievalEvent;
import org.soekrat.engine.wheel.retrieval.RetrievalEventSource;
import org.soekrat.engine.wheel.retrieval.RetrievalEventType;

/**
 * <p>
 *   {@link Mine}
 *   {@link Ontology spoke}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class MineOntology extends Ontology 
{
  private final RetrievalEventSource m_source=RetrievalEventSource.MINE;
  
  private final RetrievalEventType m_step=RetrievalEventType.STEP;
  
  private final Mine m_mine;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param wheel {@link Wheel} {@code this} 
   *              {@link Ontology} belong to.
   * @param mine  {@link Mine} {@code this} "mines".
   */
  public MineOntology(Wheel wheel, Mine mine)
  { 
    super(wheel);
    
    if (mine==null)
    {
      throw new NullPointerException("mine");
    }
    
    m_mine=mine;
  }
  
  /**
   * <p>
   *   Gets 
   *   {@link Mine} {@code this} access.
   * </p>
   * @return {@code Mine}.
   */
  public Mine getMine(){ return m_mine; }
  
  @Override
  public OntologyDatastructure getOntologyDatastructure(){ return m_mine; }
  
  @Override
  protected Object scan(Input keywords) 
  {
    return new MineScan(m_mine, keywords);
  }

  @Override
  protected RetrievalEvent paint(Object scan, List<AttributeObject> paint) 
  {
    RetrievalEvent retVal=new RetrievalEvent("Mine", m_step, m_source);
    MineRetrievalStrategy.retrieveInWheel((MineScan)scan, paint, retVal);
    return retVal;
  }

  @Override
  public Input getTokens(List<AttributeObject> paint) 
  {
    if (paint==null)
    {
      throw new NullPointerException("paint");
    }
    
    Input retVal=new Input();
    
    for (AttributeObject curr : paint)
    {
      if (curr instanceof Resource) retVal.add(curr.getName());    
    }
    
    return retVal;
  }
  
  @Override
  public List<SoekratName> getSoekratNames(List<SoekratName> names) 
  {
    names=(names==null) ? new ArrayList<SoekratName>() : names;
    
    for (Resource resource : m_mine)
    {
      names.add(resource.getSoekratName());
      Tags tags=resource.getTags();
      if (tags!=null)
      {
        for (SoekratName soekratName : tags) names.add(soekratName);
      }
    }
    
    return names;
  }

  public String getName(){ return "Mine Ontology"; }

}
